<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Eenendertigen</title>
    </head>

    <body>
        <%
            control.GameServer gameServer = control.GameServer.getInstance();
            String games = "";
            for (model.Game g : gameServer.getGames()) {
                games += g.getTable().getName() + ";" + g.getAmountOfPlayers() + ";";
            }
            String[] currentGames = games.split(";");
        %>

        <h1 align="center">Huidige spellen</h1>

        <form action="MainServlet" method="post">
            <table align="center" cellspacing="5" cellpadding="5" border="1">
                <tr>
                    <td align="center">Spel naam</td>
                    <td align="center">Aantal spelers</td>
                    <td align="center">Aanmelden</td>
                </tr>
                <%
            for (int i = 0; i < currentGames.length; i++) {
                %>
                <tr>
                    <td align="left"><%= currentGames[i++]%></td>
                    <td align="center"><%= currentGames[i]%></td>
                    <%
                    int amountOfPlayers = Integer.parseInt(currentGames[i]);
                    if (amountOfPlayers < model.Table.TABLE_SIZE) {
                    %>
                    <td align="center"> 
                        <input type="submit" value="Aansluiten">
                        <input type="hidden" name="table" value="<%=i-1%>">
                    </td>
                        <%
                        } else {
                        %>
                    <td></td>
                    <%
                        }
                    %>
                </tr>
                <%
            }
                %>
            </table>

            <h1 align="center"><input type="submit" name="action"value="Nieuw spel"></h1>
        </form>
    </body>
</html>
